package com.detector.service.detector;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.detector.common.Pages;
import com.detector.dao.detector.DetectorInfoMapper;
import com.detector.entity.detector.DetectorInfo;

@Service
public class DetectorInfoService {
	private final Logger logger = LoggerFactory.getLogger(DetectorInfoService.class);

	@Resource
	private DetectorInfoMapper detectorInfoMapper;

	public List<DetectorInfo> list(DetectorInfo detectorinfo) {
		return detectorInfoMapper.list(detectorinfo);
	}

	public PageInfo<DetectorInfo> listPage2(DetectorInfo detectorinfo, Pages pages) {
		PageHelper.startPage(pages.getPageNum(), pages.getPageSize(), true);
		List<DetectorInfo> DetectorInfoList = detectorInfoMapper.listAll(detectorinfo);
		PageInfo<DetectorInfo> pageInfo = new PageInfo<DetectorInfo>(DetectorInfoList);
		return pageInfo;
	}

	public PageInfo<DetectorInfo> listPage(DetectorInfo detectorinfo, Pages pages) {
		PageHelper.startPage(pages.getPageNum(), pages.getPageSize(), true);
		List<DetectorInfo> DetectorInfoList = detectorInfoMapper.list(detectorinfo);
		PageInfo<DetectorInfo> pageInfo = new PageInfo<DetectorInfo>(DetectorInfoList);
		return pageInfo;
	}

	public DetectorInfo selectByPrimaryKey(long id) {
		return detectorInfoMapper.selectByPrimaryKey(id);

	}

	// @Transactional(rollbackFor = RuntimeException.class)
	public DetectorInfo insertSelective(DetectorInfo detectorinfo) {
		detectorinfo.setUpdTime(new Date());
		detectorinfo.setAddTime(new Date());
		detectorInfoMapper.insertSelective(detectorinfo);
		return detectorinfo;
	}

	public DetectorInfo updateSelective(DetectorInfo detectorinfo) {
		detectorinfo.setUpdTime(new Date());
		detectorInfoMapper.updateByPrimaryKeySelective(detectorinfo);
		return detectorinfo;
	}

	/**
	 * 删除cateId
	 * 
	 * @param
	 * @return
	 */
	public int deleteByCateId(Long cateId) {
		return detectorInfoMapper.deleteByCateId(cateId);
	}

}
